﻿''' <summary>
''' 设备组头部信息
''' </summary>
''' <remarks></remarks>
Public Class DevGroupCaption

    ''' <summary>
    ''' 机组设备编号
    ''' </summary>
    ''' <remarks></remarks>
    Private _DevGroupID As Integer = 0

    ''' <summary>
    ''' 机组名称
    ''' </summary>
    ''' <remarks></remarks>
    Private _Name As String = ""

    ''' <summary>
    ''' 压缩机数量
    ''' </summary>
    ''' <remarks></remarks>
    Private _Count As Integer = 1

    ''' <summary>
    ''' 设备连接类型
    ''' </summary>
    ''' <remarks></remarks>
    Private _Type As DeviceGroupTypes = DeviceGroupTypes.DevSingle

    ''' <summary>
    ''' 默认构造函数
    ''' </summary>
    ''' <remarks>需要调用<see cref=" SetCaption ">SetCaption</see>进行赋值操作。</remarks>
    Public Sub New()

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。

    End Sub

    ''' <summary>
    ''' 使用带机组编号的构造函数
    ''' </summary>
    ''' <param name="csId">机组编号</param>
    ''' <remarks>系统自动初始化其他参数并显示</remarks>
    Public Sub New(ByVal csId As Integer)

        _DevGroupID = csId

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。

        Init()
    End Sub

    ''' <summary>
    ''' 初始化机组信息
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Init()
        '' 定义数据集
        Dim ds As DataSet = New DataSet()

        Dim dal As CcapCompressorSetItemService = New CcapCompressorSetItemService()
        ds = (dal.GetCompressorSet(_DevGroupID))
        If (ds IsNot Nothing) AndAlso ds.Tables(0).Rows.Count > 0 Then
            Dim dr As DataRow
            dr = ds.Tables(0).Rows(0)
            Me._Name = dr(1).ToString()
            Me._DevGroupID = CInt(dr(0))
            Me._Count = CInt(dr(3))
            If (dr(2).ToString() = "0") Then
                Me._Type = DeviceGroupTypes.DevSingle
            Else
                Me._Type = DeviceGroupTypes.DevMultiple
            End If
        End If
        
        updateValue()
    End Sub


    ''' <summary>
    ''' 设置控件的值
    ''' </summary>
    ''' <param name="id">机组编号</param>
    ''' <param name="strName">机组名称</param>
    ''' <param name="iCount">机组数量</param>
    ''' <remarks></remarks>
    Public Sub SetCaption(ByVal id As Integer, ByVal strName As String, ByVal iCount As Integer)
        If iCount > 1 Then
            Me._Type = DeviceGroupTypes.DevMultiple
        Else
            Me._Type = DeviceGroupTypes.DevSingle
        End If
        Me._Count = iCount
        Me._Name = strName
        Me._DevGroupID = id

        updateValue()
    End Sub

    ''' <summary>
    ''' 更新控件
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub updateValue()
        Me.lblCount.Text = Me._Count.ToString()
        Me.lblName.Text = Me._Name
        Select Case Me._Type
            Case DeviceGroupTypes.DevSingle
                Me.lblType.Text = "冷凝机组"
            Case DeviceGroupTypes.DevMultiple
                Me.lblType.Text = "并联机组"
        End Select
    End Sub
End Class

Public Enum DeviceGroupTypes
    ''' <summary>
    ''' 冷凝机组
    ''' </summary>
    ''' <remarks></remarks>
    DevSingle = 1

    ''' <summary>
    ''' 并联机组
    ''' </summary>
    ''' <remarks></remarks>
    DevMultiple = 2
End Enum
